/**
 * 
 */
package es.cloudcast.persistence.dao.jdo;

import java.io.Serializable;

import es.cloudcast.persistence.PersistenceException;
import es.cloudcast.persistence.dao.BasicCRUDDAO;
import es.cloudcast.persistence.jdo.action.ActionProcessor;
import es.cloudcast.persistence.jdo.action.basic.DeleteAction;
import es.cloudcast.persistence.jdo.action.basic.SaveAction;
import es.cloudcast.persistence.model.BasicModel;

/**
 * @author Samuel García Martínez <in0de>
 *
 */
public class BasicJDOCRUDDAO<T extends BasicModel, PK extends Serializable>
				extends BasicJDOQueryDAO<T, PK> implements BasicCRUDDAO<T, PK> {
	
	public BasicJDOCRUDDAO(PersistenceManagerFactory PMF) {
		super(PMF);
	}
	
	/*
	 * (non-Javadoc)
	 * @see es.cloudcast.persistence.dao.BasicCRUDDAO#create(es.cloudcast.persistence.model.BasicModel)
	 */
	@SuppressWarnings("unchecked")
	public T create(T transientInstance) throws PersistenceException {
		return (T) ActionProcessor.process(new SaveAction(transientInstance), PMF);
	}

	/*
	 * (non-Javadoc)
	 * @see es.cloudcast.persistence.dao.BasicCRUDDAO#createOrUpdate(es.cloudcast.persistence.model.BasicModel)
	 */
	@SuppressWarnings("unchecked")
	public T createOrUpdate(T instance) throws PersistenceException {
		return (T) ActionProcessor.process(new SaveAction(instance), PMF);
	}

	/*
	 * (non-Javadoc)
	 * @see es.cloudcast.persistence.dao.BasicCRUDDAO#delete(es.cloudcast.persistence.model.BasicModel)
	 */
	public void delete(T persistentInstance) throws PersistenceException {
		ActionProcessor.process(new DeleteAction(persistentInstance), PMF);
	}

	/*
	 * (non-Javadoc)
	 * @see es.cloudcast.persistence.dao.BasicCRUDDAO#update(es.cloudcast.persistence.model.BasicModel)
	 */
	@SuppressWarnings("unchecked")
	public T update(T persistentInstance) throws PersistenceException {
		return (T) ActionProcessor.process(new SaveAction(persistentInstance), PMF);
	}

}
